package com.study.service.impl;

import com.study.entity.Emp;
import com.study.entity.LoginInfo;
import com.study.mapper.LoginMapper;
import com.study.service.LoginService;
import com.study.utils.JwtUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
@Slf4j
@Service
public class LoginServiceImpl implements LoginService {
    @Autowired
    private LoginMapper loginMapper;
    @Override
    public LoginInfo login(Emp emp) {
        LoginInfo li =  loginMapper.login(emp);
        Map<String,Object> map = new HashMap<>();
        map.put("id",li.getId());
        map.put("username",li.getUsername());
        String token = JwtUtils.generateJwt(map);
        li.setToken(token);
        log.info("token:{}",token);
        return li;
    }
}
